import { service, crudParamsSerializer } from '@/utils/request'
import { CreateQueryParams } from '@nestjsx/crud-request'
import { Artist } from './artist.dto'

export const defaultArtistData: Partial<Artist> = {
  name: '',
  alternateNames: [] as string[],
  gender: null,
  birthday: null,
  description: '',
  images: [] as string[],
  visible: false
}

export function getArtists (params: CreateQueryParams) {
  return service.request({
    url: '/resources/artists',
    method: 'get',
    params,
    paramsSerializer: crudParamsSerializer
  })
}

export function getArtistById (id: number | string, params: CreateQueryParams) {
  return service.request({
    url: `/resources/artists/${id}`,
    method: 'get',
    params,
    paramsSerializer: crudParamsSerializer
  })
}

export function createArtist (data: Partial<Artist>, params?: CreateQueryParams) {
  return service.post<Artist>(
    '/resources/artists',
    data,
    {
      params,
      paramsSerializer: crudParamsSerializer
    }
  )
}

export function updateArtist (id: number | string, data: Partial<Artist>, params?: CreateQueryParams) {
  return service.patch<Artist>(
     `/resources/artists/${id}`,
     data, {
       params,
       paramsSerializer: crudParamsSerializer
     }
  )
}
